package edu.pku.taas.hyperic.monitor;

import java.io.IOException;
import java.util.Properties;

import org.hyperic.hq.hqapi1.HQApi;

public class HQApiHelper {
	private final String HOST;
	private final int PORT;
	private final int SSL_PORT;
	private final boolean IS_SECURE;
	private final String USER;
	private final String PASSWORD;

	private static HQApiHelper handler = new HQApiHelper();

	private HQApiHelper() {

		Properties pro = new Properties();

		try {
			pro.load(HQApiHelper.class.getResourceAsStream("monitor.conf"));
			System.out.println(pro);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		}

		HOST = pro.getProperty("hq.monitor.server.host");
		PORT = Integer.parseInt(pro.getProperty("hq.monirot.server.port"));
		SSL_PORT = Integer.parseInt(pro
				.getProperty("hq.monitor.server.sslPort"));
		IS_SECURE = Boolean.parseBoolean(pro
				.getProperty("hq.monitor.server.isSercure"));
		USER = pro.getProperty("hq.monitor.server.user");
		PASSWORD = pro.getProperty("hq.monitor.password");
	}

	public static HQApi getApi() {
		return new HQApi(handler.HOST, handler.PORT, handler.IS_SECURE,
				handler.USER, handler.PASSWORD);
	}

	public static HQApi getApi(boolean secure) {
		return new HQApi(handler.HOST, handler.SSL_PORT, secure, handler.USER,
				handler.PASSWORD);
	}

	public static HQApi getApi(String user, String password) {
		return new HQApi(handler.HOST, handler.PORT, handler.IS_SECURE, user,
				password);
	}
	
	public static void main(String[] args) throws Exception{
		System.out.println(handler.HOST);
	}
}
